<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
</body>

</html>
<script>
    
    // 图片实现懒加载原理 
    let pro = new Promise((reslove, reject) => {
        let img = document.createElement('img')
        document.body.append(img)//添加元素
        img.src = 'https://th.wallhaven.cc/small/e7/e7z65r.jpg'//初始默认图片
        img.onload = () => {
            reslove(img)
            setTimeout(() => {
                img.src = 'https://th.wallhaven.cc/small/pk/pk8pzj.jpg'//定时器3s后显示的图片
            }, 3000)
        }
        img.onerror = () => {
            reject()
        }
    })

</script>